﻿using System.Collections.Generic;
using Phoenix.Xna.Framework.Serialization;

namespace Phoenix.Xna.Framework.Input.Binding
{
    /// <summary>
    /// A collection of InputBindings associated with a common ID.
    /// </summary>
    public class InputBindingCollection : List<IInputBinding>
    {
        /// <summary>
        /// Gets or sets the ID associated with the list of bindings.
        /// </summary>
        [SerializableProperty("")]
        public string ID { get; set; }

        /// <summary>
        /// Gets the binding associated with the specified action.
        /// </summary>
        /// <param name="action">The action for which to find the binding.</param>
        /// <returns>The associated binding, otherwise null.</returns>
        public IInputBinding this[string action]
        {
            get
            {
                foreach(IInputBinding b in this)
                {
                    if (string.Compare(b.Action, action) == 0)
                    {
                        return b;
                    }
                }

                return null;
            }
        }
    }
}
